package com.wolfcode.contract.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.wolfcode.contract.domain.vo.ContractVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.InputStream;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.wolfcode.common.utils.StringUtils;
import com.wolfcode.common.utils.file.FileUploadUtils;
import com.wolfcode.common.utils.uuid.IdUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;
import com.wolfcode.common.annotation.Log;
import com.wolfcode.common.core.controller.BaseController;
import com.wolfcode.common.core.domain.AjaxResult;
import com.wolfcode.common.enums.BusinessType;
import com.wolfcode.contract.domain.Contract;
import com.wolfcode.contract.service.IContractService;
import com.wolfcode.common.utils.poi.ExcelUtil;
import com.wolfcode.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 合同信息Controller
 * 
 * @author wolfcode
 * @date 2022-12-10
 */
@RestController
@RequestMapping("/contract/contract")
public class ContractController extends BaseController
{
    @Autowired
    private IContractService contractService;

    /**
     * 查询合同信息列表
     */
    @PreAuthorize("@ss.hasPermi('contract:contract:list')")
    @GetMapping("/list")
    public TableDataInfo list(Contract contract)
    {
        startPage();
        List<ContractVo> list = contractService.selectContractList(contract);
        return getDataTable(list);
    }



    /**
     * 获取合同信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('contract:contract:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(contractService.selectContractById(id));
    }

    /**
     * 新增合同信息
     */
    @PreAuthorize("@ss.hasPermi('contract:contract:add')")
    @Log(title = "合同信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(Contract contract)
    {
        return toAjax(contractService.insertContract(contract));
    }

    /**
     * 修改合同信息
     */
    @PreAuthorize("@ss.hasPermi('contract:contract:edit')")
    @Log(title = "合同信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public void edit(ContractVo contractVo)
    {
        contractService.updateContract(contractVo);
    }

    /**
     * 合同作废
     */
    @PreAuthorize("@ss.hasPermi('contract:contract:remove')")
    @Log(title = "合同信息", businessType = BusinessType.DELETE)
	@PutMapping("/{id}")
    public void remove(@PathVariable Long id)
    {
        contractService.deleteContractById(id);
    }

    /**
     * 更新审核通过状态
     */
    @PreAuthorize("@ss.hasPermi('contract:contract:pass')")
    @Log(title = "合同信息", businessType = BusinessType.UPDATE)
    @GetMapping("/pass/{id}")
    public AjaxResult pass(@PathVariable Long id)
    {
        return toAjax(contractService.updateAuditPass(id));
    }
    /**
     * 更新审核不通过状态
     */
    @PreAuthorize("@ss.hasPermi('contract:contract:reject')")
    @Log(title = "合同信息", businessType = BusinessType.UPDATE)
    @GetMapping("/reject/{id}")
    public AjaxResult reject(@PathVariable Long id)
    {
        return toAjax(contractService.updateAuditReject(id));
    }

    /**
     * 更新盖章状态
     */
    @PreAuthorize("@ss.hasPermi('contract:contract:stamp')")
    @Log(title = "合同信息", businessType = BusinessType.UPDATE)
    @GetMapping("/stamp/{id}")
    public AjaxResult stamp(@PathVariable Long id)
    {
        return toAjax(contractService.stamp(id));
    }
}
